package com.tjhk.netty.test.handlers;

import com.tjhk.netty.manager.ChannelManager;
import com.tjhk.netty.mapping.annotation.Mapping;
import com.tjhk.netty.mapping.annotation.HandlerMapper;
import com.tjhk.netty.test.model.MyMessage;
import io.netty.channel.Channel;

@HandlerMapper
public class MyEndpoint {

    @Mapping(types = 1, desc = "注册1")
    public MyMessage register(MyMessage msg, Channel channel) {
        System.out.println("进入映射器1,channelId="+channel.id().asShortText());
        System.out.println(msg);;
        MyMessage response = new MyMessage(1,0);
        response.setBody("映射器1->服务端返回消息："+msg.getBody());
        ChannelManager channelManager = ChannelManager.instance();
        // 可用于判断是否注册
        String terminalId = "123456";
        channelManager.add(terminalId,channel);
        return response;
    }
    @Mapping(types = 2, desc = "注册2")
    public void register2(MyMessage msg, Channel channel) {
        System.out.println("进入映射器2");
        MyMessage message = new MyMessage(1,0);
        message.setBody("映射器2->服务端返回消息："+msg.getBody());
        channel.close();
//        return message;
    }
//    @Mapping(types = 1, desc = "注册2")
//    public void register2(Message msg, Channel channel) {
//        System.out.println(msg+channel.id().asShortText());
//    }
}
